<template>
  <!-- 配件替换件 -->
  <div>
    <TopFilter :list="replacementTopFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="waxReplacementformA"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :isExportExcel="true"
      :onCalcExportData="exportFun"
      exportFileName="配件替换件.xlsx"
    >
      <!-- :fetchapi="fetchApi" -->
      <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" icon="el-icon-add" :disabled="searchBtn" @click="handleSearch">曾查配件号</el-button> -->
        <!-- <el-button size="small" type="primary" icon="el-icon-daochu" :disabled="exportBtn" @click="handleExport">导出</el-button> -->
        <!-- <el-button size="small" type="primary" icon="el-icon-printer" :disabled="printBtn" @click="handlePrint">打印</el-button> -->
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="publishInfo">新建</el-button>
        <AjaxButton :click="pushDialog" type="primary">发布</AjaxButton>
        <AjaxButton :click="offlineDialog" type="primary">下线</AjaxButton> -->
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getReplacePart } from '@/api/part/report/replacementQuery';
import PartNoQuery from '@/pages/part/report/replaceAndInventory/';
import moment from 'moment';
export default {
  name: 'ReplaceAndInventory',
  components: { PartNoQuery },
  mixins: [dictionary],
  props: [],
  data() {
    return {
      replacementTopFilterList: this.createReplaceAndInventionTopFilterList(),
      columns: this.createTableList(),
      fetchParams: { xhrAbort: true },
      fetchApi: getReplacePart,
      exportBtn: false,
      printBtn: false,
      searchBtn: false,
      visible: false
    };
  },
  methods: {
    exportFun(row) {
      for (const key in row) {
        switch (key) {
          case 'sheetCreatedDate':
            if (row[key]) {
              row[key] = moment(row[key]).format('YYYY-MM-DD');
            }
            break;
          case 'CONSULTANT':
            if (row[key]) {
              // row[key] = this.userList[row[key]];
            }
            break;
          case 'STOCK_QUANTITY':
          case 'OUT_PRICE':
          case 'COST_PRICE':
          case 'OUT_AMOUNT':
          case 'COST_AMOUNT':
            if (row[key]) {
              row[key] = Number(row[key]).toFixed(2);
            }
            break;
          default:
            break;
        }
      }
    },
    // 关闭弹窗
    closeDialog() {
      this.visible = false;
    },
    // 点击配件进行搜索
    searchPartsHandle() {
      this.visible = true;
    },
    // 曾查配件号
    handleSearch() {
      this.visible = true;
    },
    // 打印处理
    handlePrint() {},
    // 导出处理
    handleExport() {},
    // 展开收起调用函数
    collapseHandle() {},
    // 搜索条件改变调用方法
    changeHandle(val) {
      this.fetchParams = Object.assign({ xhrAbort: false }, val);
    },
    // 创建表单字段列表
    createTableList() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售锁',
          dataIndex: 'saleLockMark',
          sorter: true,
          filter: true,
          filterType: 'radio',
          filterItems: [
            { text: '是', value: '1' },
            { text: '否', value: '0' }
          ],
          dictItems: [
            { text: '是', value: '1' },
            { text: '否', value: '0' }
          ],
          render: props => {
            if (props.row.saleLockMark == '0') {
              return <input type="checkbox" disabled />;
            } else {
              return <input type="checkbox" checked disabled />;
            }
          }
        },
        {
          title: '配件建立日期',
          dataIndex: 'sheetCreatedDate',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '替换件代码',
          dataIndex: 'replaceCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '佣金组',
          dataIndex: 'commissGroup',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    // 创建筛选条件
    createReplaceAndInventionTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '配件号',
          fieldName: 'partNo',
          placeholder: '',
          rules: [{ required: true, message: '请选择配件号', trigger: 'blur' }]
          // unitRender: () => {
          //   return <el-button slot="append" icon="el-icon-search" onClick={this.searchPartsHandle}></el-button>;
          // }
        }
      ];
    }
  }
};
</script>

<style></style>
